package ar.edu.uba.fi.jmit.graphvisualizer.server.storage;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class ApplicationStorage<T> {
	
	
	private Map<String, PairTimeStorage<T>> monitors;
	
	public ApplicationStorage() {
		super();
		monitors = new HashMap<String, PairTimeStorage<T>>();
	}

	public void add(String monitorName, Date date, T data) {
		PairTimeStorage<T> monitorStorage = monitors.get(monitorName);
		if(monitorStorage == null) {
			monitorStorage = new PairTimeStorage<T>();
			monitors.put(monitorName, monitorStorage);
		}
		monitorStorage.add(date, data);
	}
	
	public List<Pair<T>> get(String monitorName) {
		PairTimeStorage<T> monitorStorage = monitors.get(monitorName);
		if(monitorStorage == null) {
			Logger.getLogger(this.getClass()).debug("No data info for monitor name: " + monitorName);
			return new LinkedList<Pair<T>>();
		}
		return monitorStorage.get();
	}
	
}
